package com.gz.controller;

import com.gz.entity.MyPageData;
import com.gz.exception.SystemCode;
import com.gz.service.BookCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bookCollection")
public class BookCollectionController {
    @Autowired
    BookCollectionService bookCollectionService;

    @PostMapping("/addCollection/{userId}/{bookId}")
    public ResponseEntity addCollection(@PathVariable Long userId, @PathVariable Long bookId) {
        bookCollectionService.addCollection(userId,bookId);

        return ResponseEntity.ok(SystemCode.SUCCESS_ADD_STORAGE.getMessage());
    }
    @DeleteMapping("/deleteCollection/{userId}/{bookId}")
    public ResponseEntity deleteCollection(@PathVariable Long userId, @PathVariable Long bookId) {
        bookCollectionService.deleteCollection(userId,bookId);
        return ResponseEntity.ok(SystemCode.SUCCESS_CANCEL_STORAGE.getMessage());
    }

    @PostMapping("/checkIsStorage/{userId}/{bookId}")
    public ResponseEntity checkIsStorage(@PathVariable Long userId, @PathVariable Long bookId) {
        Boolean isFavorite = bookCollectionService.checkIsStorage(userId, bookId);
        return ResponseEntity.ok(isFavorite);
    }


    @PostMapping("/selectCollectionStorageByUserId/{userId}/{pageNum}/{pageSize}")
    public ResponseEntity selectCollectionStorageByUserId(@PathVariable Long userId,
                                                          @PathVariable int pageNum,
                                                          @PathVariable int pageSize) {

        MyPageData data = bookCollectionService.getPageByBookIds(userId, pageNum, pageSize);
        return ResponseEntity.ok(data);
    }

}
